package cn.tedu.zhxy.controller;


import cn.tedu.zhxy.entity.Grade;
import cn.tedu.zhxy.service.GradeService;
import cn.tedu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {
    @Autowired
    private GradeService gradeService;

    @GetMapping("getGrades")
    public  Result  getGrades(){
        List<Grade> list = gradeService.list();
        return Result.ok(list);
    }


    @GetMapping("getGrades/{page}/{limit}")
    public  Result  getGrades(@PathVariable Long  page,@PathVariable Long  limit, String  gradeName){
        Page<Grade>  pageParam = new Page<>(page,limit);
        IPage<Grade> list = gradeService.getGradsByOpr(pageParam,gradeName);
        return Result.ok(list);
    }

    @PostMapping("saveOrUpdateGrade")
    public  Result  saveOrUpdateGrade(@RequestBody  Grade  grade){
        gradeService.saveOrUpdate(grade);
        return Result.ok(null);
    }
    @DeleteMapping("deleteGrade")
    public  Result  deleteByIds(@RequestBody List<Integer> idList){
        gradeService.removeByIds(idList);
        return  Result.ok();
    }

}

